package com.xxk.rocket.star.jackson;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.xxk.rocket.star.core.context.ProducerContext;
import com.xxk.rocket.star.core.process.IStargateClientEncod;
import com.xxk.rocket.star.core.vo.StargateMessage;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class JacksonStargateClientEncode implements IStargateClientEncod {

  private ObjectMapper objectMapper = new ObjectMapper();

  @Override
  public byte[] encode(StargateMessage stargateMessage, ProducerContext producerContext) {
    try {
      byte[] bytes = new byte[0];
      bytes = objectMapper.writeValueAsBytes(stargateMessage);
      return bytes;
    } catch (Throwable e) {
      log.error("JacksonStargateClientEncode :", e);
      return null;
    }
  }
}
